package com.heima.wemedia.controller.v1;


import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(value = "素材管理API",tags = "素材管理API")
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    //依赖注入
    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 素材上传
     * @param multipartFile
     * @return
     */
    @ApiOperation("素材上传")
    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile){
        return wmMaterialService.upload(multipartFile);
    }

    /**
     * 素材查询
     * @param dto
     * @return
     */
    @ApiOperation("素材查询")
    @PostMapping("/list")
    public ResponseResult findlist(@RequestBody WmMaterialDTO dto){
        return wmMaterialService.findList(dto);
    }

    /**
     * 删除素材
     * @param id
     * @return
     */
    @ApiOperation("删除素材")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable("id")Integer id){
        return wmMaterialService.delete(id);
    }

    @ApiOperation("图片收藏")
    @GetMapping("/collect/{id}")
    public ResponseResult updatecollect(@PathVariable("id") Integer id){
        return wmMaterialService.updatePictur(id, WemediaConstants.COLLECT_MATERIAL);
    }

    @ApiOperation("取消图片收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult updatecancel(@PathVariable("id") Integer id){
        return wmMaterialService.updatePictur(id,WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }
}
